package com.sakuracard.stepdemo;

import com.sakuracard.stepdemo.util.json.JsonUtils;
import com.sakuracard.stepdemo.web.converter.CustomFormMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Configuration
public class StepDemoWebMvcConfigurer implements WebMvcConfigurer {


  @Override
  public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(JsonUtils.getGson());
    List<MediaType> mediaTypes = new ArrayList<>();
    mediaTypes.add(MediaType.APPLICATION_JSON);
    mediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
    converter.setSupportedMediaTypes(mediaTypes);
    converters.addFirst(converter);
  }
}
